home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v2.1 / Amiga Developer CD v2.1.iso / Contributions / Haage_&_Partner / Storm-Projects / NDKExamples1 / compatibility / maxdepthlores.c < prev    next >
C/C++ Source or Header  |  1999-04-16  |  4KB  |  119 lines

  1. /*  maxdepthlores.c
  2.  *
  3.  * (c) Copyright 1992-1996 Amiga International, Inc. All rights reserved.
  4.  *
  5.  * This software is provided as-is and is subject to change; no warranties
  6.  * are made.  All use is at your own risk.  No liability or responsibility
  7.  * is assumed.
  8.  *
  9.  */
  10.  
  11. #include <exec/types.h>
  12. #include <intuition/intuition.h>
  13. #include <graphics/displayinfo.h>
  14. #include <dos/dos.h>
  15.  
  16. #include <clib/exec_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include <clib/graphics_protos.h>
  19. #include <clib/dos_protos.h>
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23.  
  24. struct Library *IntuitionBase;
  25. struct Library *GfxBase;
  26.  
  27. void Quit(char *whytext,LONG failcode)
  28. {
  29.     if(*whytext) printf("%s\n",whytext);
  30.  
  31.     if (IntuitionBase)    CloseLibrary(IntuitionBase);
  32.     if (GfxBase)    CloseLibrary(GfxBase);
  33.  
  34.     exit(failcode);
  35. }
  36.  
  37. void main(void)
  38. {
  39.     ULONG modeID = LORES_KEY;
  40.     DisplayInfoHandle displayhandle;
  41.     struct DimensionInfo dimensioninfo;
  42.  
  43.     UWORD maxdepth, maxcolors;
  44.     ULONG soerror = NULL,colornum;
  45.     struct Screen *screen;
  46.  
  47.     if ((GfxBase = OpenLibrary("graphics.library",36))==NULL)
  48.         Quit("graphics.library is too old <V36",RETURN_FAIL);
  49.  
  50.     if ((IntuitionBase = OpenLibrary("intuition.library",36))==NULL)
  51.         Quit("intuition.library is too old <V36",RETURN_FAIL);
  52.  
  53.     if ((displayhandle=FindDisplayInfo(modeID))==NULL)
  54.         Quit("modeID not found in display database",RETURN_FAIL);
  55.  
  56.     if (GetDisplayInfoData(displayhandle,(UBYTE *) &dimensioninfo,
  57.     sizeof(struct DimensionInfo),DTAG_DIMS,NULL)==0)
  58.         Quit("mode dimension info not available",RETURN_FAIL);
  59.  
  60.     maxdepth=dimensioninfo.MaxDepth;
  61.     printf("dimensioninfo.MaxDepth=%d\n",(int) maxdepth);
  62.  
  63.     if (screen=OpenScreenTags(NULL, SA_DisplayID    ,modeID,
  64.                                     SA_Depth        ,(UBYTE) maxdepth,
  65.                                     SA_Title        ,"MaxDepth LORES",
  66.                                     SA_ErrorCode    ,&soerror,
  67.                                     SA_FullPalette  ,TRUE,
  68.                                     TAG_END))
  69.         {
  70.             /* Zowee! we actually got the screen open!
  71.              * now let's try drawing into it.
  72.              */
  73.             maxcolors=1<<maxdepth;
  74.  
  75.             printf("maxcolors=%d\n",(int) maxcolors);
  76.  
  77.             for(colornum=0;colornum<maxcolors;++colornum)
  78.             {
  79.                 SetAPen(&(screen->RastPort),colornum);
  80.                 Move(&(screen->RastPort),colornum,screen->BarHeight + 2);
  81.                 Draw(&(screen->RastPort),colornum,screen->Height - 1);
  82.             }
  83.             Delay(TICKS_PER_SECOND * 6);
  84.  
  85.             CloseScreen(screen);
  86.         }
  87.     else
  88.         {   /* Hmmm.  Couldn't open the screen.  maybe not
  89.              * enough CHIP RAM? Maybe not enough chips! ;-)
  90.              */
  91.             switch(soerror)
  92.             {
  93.                 case OSERR_NOCHIPS:
  94.                     Quit("Bummer! You need new chips dude!",RETURN_FAIL);
  95.                     break;
  96.  
  97.                 case OSERR_UNKNOWNMODE:
  98.                     Quit("Bummer! Unknown screen mode.",RETURN_FAIL);
  99.                     break;
  100.  
  101.                 case OSERR_NOCHIPMEM:
  102.                     Quit("Not enough CHIP memory.",RETURN_FAIL);
  103.                     break;
  104.  
  105.                 case OSERR_NOMEM:
  106.                     Quit("Not enough FAST memory.",RETURN_FAIL);
  107.                     break;
  108.  
  109.                 default:
  110.                     printf("soerror=%d\n",soerror);
  111.                     Quit("Screen opening error.",RETURN_FAIL);
  112.                     break;
  113.             }
  114.             Quit("Couldn't open screen.",RETURN_FAIL);
  115.         }
  116.  
  117. Quit("",RETURN_OK);    /* clean up and exit */
  118. }
  119.